package com.example.RuanJianKeShe.Service.manager.add;

import com.alibaba.fastjson.JSON;
import com.example.RuanJianKeShe.Bean.TC;
import com.example.RuanJianKeShe.Dao.impl.TeaCourseDaoImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/addTCInfo")
public class addTCInfo extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("utf-8");
        System.out.println(req.getParameter("msg"));
        TC tc = new TC();
        tc.setCno(Integer.parseInt(req.getParameter("cno")));
        tc.setTno(Integer.parseInt(req.getParameter("tno")));
        tc.setTeachTime(req.getParameter("teachTime"));
        tc.setTeachWeek(req.getParameter("teachWeek"));
        TeaCourseDaoImpl teaCourseDao = new TeaCourseDaoImpl();
        Boolean flag = teaCourseDao.addTeacherCourse(tc);
        if (flag==true){
            String jsonString = JSON.toJSONString("success");
            resp.getWriter().write(jsonString);
        }else{
            String jsonString = JSON.toJSONString("fail");
            resp.getWriter().write(jsonString);
        }
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        this.doGet(req,resp);
    }
}
